package com.yc.http.v1;

import java.io.IOException;

public class HttpServletImpl implements HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        switch (request.getMethod()){
            case "GET":
                doGet(request,response);
                break;
            case "POST":
                doPost(request,response);
                break;
            case "OPTIONS":
                doOptions(request,response);
                break;
            // .... TODO
            default:
                throw new ServletException("不支持的方法+"+ request.getMethod());
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void doTrace(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误!");
    }

    @Override
    public void init() {

    }

    @Override
    public void destroy() {

    }
}
